In an ordinary decoder, received encoded data is stored in a buffer until the data is decoded to be displayed. The decoded encoded data is withdrawn from the buffer.
When encoding a video image, the state of the decoder-side buffer should be considered so as to prevent a result that the video cannot be decoded. Accordingly, a test using a virtual decoder buffer is performed during the encoding, so as to ensure that the decoding will succeed.
The decoder buffer has two abnormal states, that is, overflow and underflow.
In the overflow, encoded data reaches the decoder at a speed higher than a speed for decoding and displaying the data. If receiving encoded data at a speed higher than the decoding and displaying speed, the amount of code for the received data is larger than the amount of code for data withdrawn from the buffer, so that the amount of received data may exceed the capacity of the decoder buffer. In a known measure to prevent the overflow of the decoder buffer, useless data (for data staffing or filling) are inserted so as to reduce the speed for receiving necessary data, thereby preventing the overflow.
In contrast, in the underflow, necessary encoded data has not yet been received when decoding and displaying the data. In order to prevent the underflow, an appropriate target amount of code for preventing the underflow may be set so as to control the amount of generated code. In another method using a picture skip technique, the number of pictures to be encoded is reduced so as to prevent the underflow. Both methods prevent the underflow by suppressing the amount of generated code.
For example, Patent Document 1 discloses a method which performs a decoder buffer examination for determining whether or not an underflow has occurred. If an underflow has occurred, original encoded data is replaced with skip encoded data.
FIG. 7 shows an operation flow of an underflow prevention method in conventional video encoding.
First, in the decoder buffer examination, it is determined whether or not an underflow has occurred (see step S100). If an underflow is detected, the amount of generated code is suppressed through a generated code amount control process (see step S101).
Suppression of the amount of generated code may be performed by a control method for reducing the difference between the amount of generated code and the target amount of code, a method of skipping a picture for which an underflow is detected, or a method of generating dummy encoded data which produces a minimum amount of generated code.
The detection of occurrence of the underflow is executed before or after the relevant encoding.
If executing the underflow detection after the encoding, an encoded stream of the picture for which the underflow has been detected should be cancelled.
In addition, the rate of occupancy in the decoder buffer immediately before the decoding of a picture at time t can be computed by the following formula.B(t)=B(0)+R*t−ΣG(i)where B(0) is an initial value of the rate of occupancy in the decoder buffer, R denotes a bit rate, and G(i) denotes the amount of code generated for a picture at time i.